<template>
	<view class="ingredients-list">
		<view class="basic-info">
			<view class="time-required">
				<image src="../../static/img/vip-menu/shijian.png"
					mode=""></image>
				<text>{{menuDetail.needtime}}分钟</text>
			</view>

			<view class="level-required">
				<image src="../../static/img/vip-menu/xing.png"
					mode=""></image>
				<text>切墩 （初级）</text>
			</view>
		</view>

		<view class="i-list">
			<view class="list-title">
				<text>用料</text>
				<text v-if="isCollected"
					@tap="handleTapCollect">已收藏</text>
				<text v-else
					@tap="handleTapCollect"
					class="add-collection">加入收藏</text>
			</view>

			<view class="list-item"
				v-for="item in menuDetail.ingredient"
				:key="item.name">
				<text class="ingredient">{{item.name}}</text>
				<text class="quantity">{{item.number}}</text>
			</view>




		</view>

	</view>
</template>

<script>
	export default {
		name: "ingredients-list",
		props: {
			menuDetail: {
				type: Object
			},
			isCollected:{
				type:Boolean
			}
		},
		created() {
			this.userInfo = getApp().globalData.userInfo;

		},
		data() {
			return {
				userInfo: null,
			};
		},
		methods: {
			async handleTapCollect() {
				let res = await this.$api.personal.collect(this.userInfo._id, this.menuDetail._id);
				// console.log(res);
				if (res.code) {
					this.$emit('collectMenu')
					uni.showToast({
						title: res.msg,
						icon: 'success'
					})
				} else {
					this.$emit('collectMenu')
					uni.showToast({
						title: res.msg,
						icon: 'error'
					})
				}
			}
		}
	}
</script>

<style lang="scss"
	scoped>
	.ingredients-list {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 750rpx;
		// height: 500rpx;
		padding-bottom: 40rpx;
		background-color: #fff;

		.basic-info {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 100%;
			height: 92rpx;
			line-height: 92rpx;

			.time-required,
			.level-required {
				width: fit-content;
				height: fit-content;
				margin-right: 20rpx;
				display: flex;
				align-items: center;
				font-size: 26rpx;
				color: #686868;

				image {
					width: 36rpx;
					height: 36rpx;
					margin-right: 12rpx;
				}
			}
		}

		.i-list {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 100%;
			box-sizing: border-box;
			padding: 0 32rpx;

			.list-title {
				display: flex;
				justify-content: space-between;
				width: 100%;
				padding-bottom: 34rpx;
				// border-bottom: ;
				border-bottom: solid 2rpx #c5c5c5;

				text {
					&:first-of-type {
						font-size: 28rpx;
						font-weight: bold;
						color: #2c2c2c;
					}


					&:last-of-type {
						font-size: 30rpx;
						color: #ee7f33;

						&.add-collection {
							color: #aaaaaa;
						}
					}
				}
			}

			.list-item {
				display: flex;
				justify-content: space-between;
				width: 100%;
				height: 75rpx;
				padding: 16rpx 0;
				box-sizing: border-box;
				border-bottom: solid 2rpx #c5c5c5;

				text {
					width: 50%;
					max-width: 50%;
					color: #707070;
					font-size: 28rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
		}
	}
</style>
